package com.rpay.dao.news;

import com.rpay.model.news.NewsDO;
import com.rpay.model.news.SqlQueryDO;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class NewsDao {
    @Autowired
    @Qualifier("readSqlSession")
    private SqlSessionTemplate readSqlSession;

    @Autowired
    @Qualifier("writeSqlSession")
    private SqlSessionTemplate writeSqlSession;

    public List<NewsDO> selectDataList(SqlQueryDO sqlQueryDO) {
        return readSqlSession.selectList("rpay.news.selectDataList", sqlQueryDO);
    }
    public Integer selectCount(SqlQueryDO sqlQueryDO) {
        return readSqlSession.selectOne("rpay.news.selectCount", sqlQueryDO);
    }

    public int insert(NewsDO newsDO) {
        return writeSqlSession.insert("rpay.news.insert", newsDO);
    }

    public NewsDO findById(NewsDO newsDO) {
        return readSqlSession.selectOne("rpay.news.findById", newsDO);
    }

    public int deleteById(Integer id) {
        return writeSqlSession.update("rpay.news.deleteById", id);
    }

    public int updateById(NewsDO newsDO) {
        return writeSqlSession.update("rpay.news.updateById", newsDO);
    }
}
